#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from xpy3lib.XRetryableQuery import XRetryableQuery
from xpy3lib.XLogger import XLogger

def DP011MJob__df7(db_conn_dbprod7=None,
                   db_conn_rds=None,
                   data_type=None,
                   account=None,
                   cost_center_org=None,
                   unit=None,
                   account_period_start=None,
                   account_period_end=None):
    """
    DP011MJob的df7

    :param db_conn_dbprod7:
    :param wce_org:
    :param data_type:
    :param account:
    :param cost_center_org:
    :param unit:
    :param account_period_start:
    :param account_period_end:
    :return:
    """
    sql = " SELECT " \
          " REC_ID," \
          " ACCT AS ACCOUNT," \
          " DEPARTMENT_CODE AS FACTORY," \
          " UNIT_CODE AS UNIT," \
          " CLASS AS TEAM," \
          " SHIFT," \
          " COST_CENTER," \
          " PRODUCE_TIME AS WORK_TIME," \
          " PRODUCE_START_TIME AS PROCESS_START_TIME," \
          " PRODUCE_END_TIME AS PROCESS_END_TIME," \
          " BYPRODUCT_CODE AS PRODUCT_CODE," \
          " STEELNO AS ST_NO," \
          " INPUT_BYPRODUCT_CODE as IN_PRODUCT_CODE," \
          " PROD_COILNO as MAT_NO," \
          " ENTRY_COILNO AS IN_MAT_NO," \
          " APPTHROWAIMODE AS APP_THROW_AI_MODE," \
          " ANNEAL_CURVE AS DESIGN_ANNEAL_DIAGRAM_CODE," \
          " TRIM_FLAG," \
          " MAT_ACT_WIDTH," \
          " MAT_ACT_THICK," \
          " ENTRY_MAT_WIDTH AS IN_MAT_WIDTH," \
          " ENTRY_MAT_THICK AS IN_MAT_THICK," \
          " PLAN_NO," \
          " TRIMMING_AMT AS TRIM_WIDTH," \
          " ENTRY_MAT_INDIA AS IN_MAT_INNER_DIA," \
          " CUST_ORDER_NO," \
          " PICKLING_TRIMMING_FLAG AS PICKL_TRIM_FLAG," \
          " SORT_GRADE_CODE," \
          " COATING_TYPE AS LAYER_TYPE," \
          " MAT_ACT_LEN," \
          " MAT_ACT_AREA," \
          " TOP_COATING_WT as TOP_COAT_WT," \
          " BOT_COATING_WT as BOT_COAT_WT," \
          " COALESCE(OUTPUT_WT,0) AS WT," \
          " ACT_OUTPUT_WT AS ACT_WT," \
          " INPUT_WT AS IN_WT," \
          " ACT_INPUT_WT AS ACT_IN_WT," \
          " 'T' AS CONSUME_UNIT," \
          " '%s' AS DATA_TYPE," \
          " 'BGRAGGCB' AS REC_REVISOR," \
          " TO_CHAR(CURRENT TIMESTAMP,'YYYYMMDDHH24MISS') AS REC_REVISOR_TIME," \
          " 'BGRAGGCB' AS REC_CREATOR," \
          " TO_CHAR(CURRENT TIMESTAMP,'YYYYMMDDHH24MISS') AS REC_CREATE_TIME," \
          " PRODUCE_NICK_FLAG AS LAS_NOTCH_FLAG" \
          " FROM " \
          " BGTARAS1.T_ADS_FACT_SICB_DP0102" \
          " WHERE 1=1 " \
          " AND ACCT = '%s' " \
          " AND COST_CENTER = '%s' " \
          " AND UNIT_CODE='%s' " \
          " AND DATA_TYPE = '%s'" \
          " AND LEFT(PRODUCE_TIME,14) >='%s'" \
          " AND LEFT(PRODUCE_TIME,14) <'%s'" % (
                                             data_type,
                                             account,
                                             cost_center_org,
                                             unit,
                                             data_type,
                                             account_period_start,
                                             account_period_end)
    XLogger.getInstance().logger.info(sql)
    df = XRetryableQuery(p_db_conn=db_conn_rds, p_sql=sql, p_max_times=5).redo()
    df.columns = df.columns.str.upper()
    XLogger.getInstance().logger.info(df)
    success = df.empty is False
    return df
